<!-- eslint-disable vue/multi-word-component-names -->
<template>
    <div>
        <div class="menu-container">
          <div class="menu-box" v-for="item in dataList" :key="item.module_name">
            <el-card class="card-item" @click="handleMenu(item)">
              <img  alt="none" class="img-item" :src='item.module_icon_real_path'>
            </el-card>
            <el-row>
              <span class="text-item"> {{item.module_name}}</span>
            </el-row>
          </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { ref,watch } from 'vue';
import router from '@/router/index'
import { moduleStore, type StateModuleItemType } from '@/stores/moduleStore';
  const props = defineProps<{moduleList : Array<StateModuleItemType>}>();//主界面参数
  const dataList = ref<Array<StateModuleItemType>>([]);//菜单数据
  //点击模块
  const handleMenu = (menuItem: StateModuleItemType)=>{
    console.log(menuItem)
    //缓存当前进入的模块
    moduleStore().setActiveModule(menuItem);
  //根据权限获取 对应模块的 第一个菜单 路由名称 然后跳转
  router.push({
    path: 'default-idoo',
    query: {
      module_key: menuItem.module_key,
      module_icon_path : menuItem.module_icon_real_path,
    }
  });
  }

  watch(() => props.moduleList,//监听主界面 菜单数据
    async (val) => {
      console.log(props.moduleList)
    if (val) {
      //构造 菜单图标对应path
      dataList.value =  props.moduleList;
    } else {
      dataList.value = [];
      return [];
    }
  },
  { deep: true, immediate: true }
);
</script>

<style  scoped>
.menu-container {
  width: 70%;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: center;
  gap: 10px;
  margin : 50px auto
}
.menu-box{
  height: 145px;
  flex: 0 0 calc(16.666% - 10px);
  box-sizing: border-box;
  margin-top: 5px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.card-item{
  transition: transform 0.2s ease;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 80px;
  height: 80px;
  cursor: pointer;
}
.card-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}
.img-item{
  width: 70%;
}
.box-item{
  height: 75px;
}
:deep(.el-card__body){
  padding:0% !important;
  display: flex;
  justify-content: center;
  align-items: center;
}
.text-item {
  font-family: "Comic Sans MS", cursive;
  font-size: 16px;
  color: #333;
  text-align: center;
  margin-top: 20px;
  font-weight: 600;
}

</style>
